package JPLXtandemGA;


public class PeakParameters implements IParameter<PeakParameters> {

	private IParameter<IntegerParameter> totalPeaks;
	private IParameter<IntegerParameter> minPeaks;
	
	public PeakParameters (IParameter<IntegerParameter> totalPeaks,IParameter<IntegerParameter> minPeaks){
		this.minPeaks = minPeaks;
		this.totalPeaks = totalPeaks;
	}

	@Override
	public IParameter<PeakParameters> mutate() {
		totalPeaks = totalPeaks.mutate();
		minPeaks = minPeaks.mutate();
		
		if( checkCondition()){
			System.out.println("Peaks range exceeded");
			mutate();
		}
		return this;
	}
	
	@Override
	public String name() {		
		return null;
	}

	@Override
	public IParameter<PeakParameters> randomize() {
		totalPeaks = totalPeaks.randomize();
		minPeaks = minPeaks.randomize();
		
		if( checkCondition()){
			System.out.println("Peaks range exceeded");
			randomize();
		}
		return this;
	}

	@Override
	public String valueToString() {
		return minPeaks.valueToString() + ";" + totalPeaks.valueToString();
	}

	@Override
	public String xmlRepresentation() {

		String xml = minPeaks.xmlRepresentation();
		xml = xml + totalPeaks.xmlRepresentation();
		return xml;
	}

	private boolean checkCondition(){
		int tPeaks = Integer.parseInt(totalPeaks.valueToString());
		int mpeaks = Integer.parseInt(minPeaks.valueToString());
		
		if( tPeaks < mpeaks)
			return true;
		else 
			return false;
		
	}
	
	public void validateAndFix(){
		if(checkCondition())
			randomize();
	}
}
